Skip to content

fix(transforms): use case-insensitive column comparison when output case settings are active#322

Merged
z3z1ma merged 2 commits intoz3z1ma:mainfrom
ota2000:ota2000/fix/case-insensitive-column-comparison
Mar 24, 2026
Merged

fix(transforms): use case-insensitive column comparison when output case settings are active#322
z3z1ma merged 2 commits intoz3z1ma:mainfrom
ota2000:ota2000/fix/case-insensitive-column-comparison

Conversation

@ota2000
Copy link
Copy Markdown
Contributor

@ota2000 ota2000 commented Feb 14, 2026

Summary

Fix broken idempotency in inject_missing_columns, remove_columns_not_in_database, and synchronize_data_types when output-to-upper or output-to-lower is active on non-Snowflake databases.

Problem

normalize_column_name() is case-preserving on non-Snowflake DBs (e.g., PostgreSQL). When combined with output case settings, the column name comparison between case-converted node columns and DB-derived incoming columns fails:

  • inject_missing_columns: re-adds existing columns on every run (e.g., "zebra" not in {"ZEBRA"})
  • remove_columns_not_in_database: incorrectly removes valid columns that exist in the DB
  • synchronize_data_types: fails to match columns, skipping data type sync

Additionally, inject_missing_columns used context.settings.output_to_upper/lower directly for data_type case conversion instead of the already-resolved node-level settings.

Fix

When output-to-upper or output-to-lower is active, normalize both sides of the comparison to lowercase. This ensures case-converted column keys match DB-derived normalized names regardless of the adapter type.

  • inject_missing_columns: case-insensitive current_columns membership check + use resolved node-level settings for data_type
  • remove_columns_not_in_database: case-insensitive set difference between current and incoming keys
  • synchronize_data_types: fallback to lowercase lookup when direct incoming_columns.get() fails

Tests

  • test_inject_missing_columns_idempotent_with_output_to_upper_on_postgres: verifies no re-addition on second run
  • test_remove_columns_not_in_database_with_output_to_upper_on_postgres: verifies valid columns are not removed
  • test_remove_columns_not_in_database_removes_truly_extra_columns: verifies truly stale columns are still removed
  • test_synchronize_data_types_with_output_to_upper_on_postgres: verifies data type sync succeeds

Depends on #321

Closes #320

When output-to-lower is enabled with Snowflake, newly injected columns
had uppercase dictionary keys from the database while sort used lowercase
comparison, causing incorrect alphabetical order on the first run.

Convert column keys and names at injection time based on output-to-lower
and output-to-upper settings so that subsequent sorting works correctly
from the first execution.
…tings are active

When output-to-upper or output-to-lower is enabled on non-Snowflake DBs,
normalize_column_name is case-preserving, causing mismatches between
case-converted node column names and DB-derived incoming column names.

This breaks idempotency in inject_missing_columns (re-adds existing columns),
remove_columns_not_in_database (incorrectly removes valid columns), and
synchronize_data_types (fails to match columns for type sync).

Fix by lowercasing both sides of the comparison when case conversion is active.
Also fix inject_missing_columns data_type case conversion to use resolved
node-level settings instead of global context.settings.

Closes z3z1ma#320
@ota2000 ota2000 marked this pull request as ready for review February 14, 2026 07:07
@z3z1ma z3z1ma merged commit 02648b2 into z3z1ma:main Mar 24, 2026
Copilot AI added a commit that referenced this pull request Mar 24, 2026
Audit of 19 merged PRs via gh CLI revealed 3 new features and 11 fixes
not captured in the initial 1.2.3 prep. Bump to minor version 1.3.0.

Added (3 new features):
- #317 fusion_compat mode for dbt 1.9.6+ / dbt Fusion YAML output
- #323 external YAML formatter integration (--formatter flag)
- #318 Python 3.13 support + ydata-profiling upgrade

Fixed (11 bug fixes):
- #310 Azure OpenAI support broken with openai>=1.0.0
- #313 Missing ColumnInfo.config in dbt-core 1.10+, ApproximateMatchError on Snowflake
- #316 --check with --dry-run returning exit 0 on changes
- #321 Column case conversion not applied to dict keys in inject_missing_columns
- #322 Case-insensitive column comparison when output case settings active
- #324 Normalize column-level meta to config.meta for dbt 1.9+
- #325 Case-insensitive Snowflake relation matching in get_columns
- #327 Skip writing empty columns array when node has no columns
- #330 Add metrics to _PRESERVED_KEYS
- #335 Fix CI regressions (writer, catalog matching, sync behavior, thread-pool)
- #336 Fix trailing whitespace in writer.py

Plus original unreleased entries (dbt-core-interface bump, column meta fix, security deps)

Co-authored-by: z3z1ma <41213451+z3z1ma@users.noreply.github.com>
Agent-Logs-Url: https://github.com/z3z1ma/dbt-osmosis/sessions/ab38a1a7-89fb-4f43-83f4-d2c3d0c9e100
z3z1ma added a commit that referenced this pull request Mar 25, 2026
* Initial plan

* chore: cut release v1.2.3

- Batch and merge changelog entries with changie
- Bump version from 1.2.2 to 1.2.3 in pyproject.toml
- Update uv.lock

Changes in this release:
- Fixed: Bump dbt-core-interface minimum version to 1.1.7
- Fixed: Keep column meta in YAML sync output while handling dbt config meta
- Security: Update docs dependency overrides and PyPI publish action

Co-authored-by: z3z1ma <41213451+z3z1ma@users.noreply.github.com>
Agent-Logs-Url: https://github.com/z3z1ma/dbt-osmosis/sessions/7844d695-ea32-43b7-9c12-ed3dba1135a8

* chore: cut release v1.3.0 with all March 24 PRs captured

Audit of 19 merged PRs via gh CLI revealed 3 new features and 11 fixes
not captured in the initial 1.2.3 prep. Bump to minor version 1.3.0.

Added (3 new features):
- #317 fusion_compat mode for dbt 1.9.6+ / dbt Fusion YAML output
- #323 external YAML formatter integration (--formatter flag)
- #318 Python 3.13 support + ydata-profiling upgrade

Fixed (11 bug fixes):
- #310 Azure OpenAI support broken with openai>=1.0.0
- #313 Missing ColumnInfo.config in dbt-core 1.10+, ApproximateMatchError on Snowflake
- #316 --check with --dry-run returning exit 0 on changes
- #321 Column case conversion not applied to dict keys in inject_missing_columns
- #322 Case-insensitive column comparison when output case settings active
- #324 Normalize column-level meta to config.meta for dbt 1.9+
- #325 Case-insensitive Snowflake relation matching in get_columns
- #327 Skip writing empty columns array when node has no columns
- #330 Add metrics to _PRESERVED_KEYS
- #335 Fix CI regressions (writer, catalog matching, sync behavior, thread-pool)
- #336 Fix trailing whitespace in writer.py

Plus original unreleased entries (dbt-core-interface bump, column meta fix, security deps)

Co-authored-by: z3z1ma <41213451+z3z1ma@users.noreply.github.com>
Agent-Logs-Url: https://github.com/z3z1ma/dbt-osmosis/sessions/ab38a1a7-89fb-4f43-83f4-d2c3d0c9e100

* fix: apply ruff-format to all 4 files failing pre-commit check

- specs/001-unified-config-resolution/data-model.md: fix string quotes, blank lines, function signature
- specs/001-unified-config-resolution/quickstart.md: fix string quotes, multiline function args
- specs/001-unified-config-resolution/research.md: fix multiline logger.debug call formatting
- src/dbt_osmosis/core/transforms.py: wrap multi-import from into parenthesized form

Co-authored-by: z3z1ma <41213451+z3z1ma@users.noreply.github.com>
Agent-Logs-Url: https://github.com/z3z1ma/dbt-osmosis/sessions/eb00bcd0-9a25-47c3-8a0c-d5ae5208651f

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: z3z1ma <41213451+z3z1ma@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: normalize_column_name does not account for output case settings on non-Snowflake DBs

2 participants